<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="日期">
        <el-date-picker
          v-model="range"
          type="daterange"
          range-separator="至"
          value-format="yyyy-MM-dd"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="所属省份" prop="city">
        <el-select
          v-model="queryParams.province"
          placeholder="请选择所属省份"
          clearable
        >
          <el-option label="河北省" value="河北省"></el-option>
          <el-option label="其他省份" value="其他省份"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属城市" prop="city">
        <el-select
          v-model="queryParams.city"
          placeholder="请选择所属城市"
          clearable
        >
          <el-option label="石家庄市" value="石家庄市"></el-option>
          <el-option label="唐山市" value="唐山市"></el-option>
          <el-option label="邯郸市" value="邯郸市"></el-option>
          <el-option label="秦皇岛市" value="秦皇岛市"></el-option>
          <el-option label="保定市" value="保定市"></el-option>
          <el-option label="张家口市" value="张家口市"></el-option>
          <el-option label="承德市" value="承德市"></el-option>
          <el-option label="廊坊市" value="廊坊市"></el-option>
          <el-option label="沧州市" value="沧州市"></el-option>
          <el-option label="衡水市" value="衡水市"></el-option>
          <el-option label="邢台市" value="邢台市"></el-option>
          <el-option label="雄安" value="雄安"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        label="所属商城"
        prop="mallId"
        v-hasPermi="['cancel:traceLogs:mallList']"
      >
        <el-select
          v-model="queryParams.mallId"
          placeholder="请选择所属商城"
          clearable
        >
          <el-option
            v-for="item in mallList"
            :key="item.id"
            :label="item.mallName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <div class="box">
      <el-card class="a1">
        <div class="boc-item">
          <div class="fons">
            券发放总数 | <span class="yesterday">{{ yesterdayTime }}</span>
          </div>
          <div class="tag">
            <el-tag class="cc" size="mini">全平台 </el-tag>
          </div>
        </div>
        <div class="box-it">
          {{ total.sendCouponMap.all }} <span class="ftz">个</span>
          |
          {{ total.sendCouponMap.yesterday }} <span class="ftz">个</span>
        </div>
        <!-- <div class="boc-item1">
          <div class="fons1">今日订单数</div>
          <div class="tag">10单</div>
        </div> -->
      </el-card>
      <el-card class="a1">
        <div class="boc-item">
          <div class="fons">
            使用券数量 | <span class="yesterday">{{ yesterdayTime }}</span>
          </div>
          <div class="tag">
            <el-tag class="cc" size="mini"> 全平台</el-tag>
          </div>
        </div>
        <div class="box-it">
          {{ total.useCouponMap.all }}<span class="ftz">个</span> |
          {{ total.useCouponMap.yesterday }}<span class="ftz">个</span>
        </div>
        <!-- <div class="boc-item1">
          <div class="fons1">今日订单数</div>
          <div class="tag">10单</div>
        </div> -->
      </el-card>
      <el-card class="a1">
        <div class="boc-item">
          <div class="fons">
            首页浏览数 | <span class="yesterday">{{ yesterdayTime }}</span>
          </div>
          <div class="tag">
            <el-tag class="cc" size="mini">全平台 </el-tag>
          </div>
        </div>
        <div class="box-it">
          {{ total.indexLookMap.all }}<span class="ftz">人</span> |
          {{ total.indexLookMap.yesterday }}<span class="ftz">人</span>
        </div>
        <!-- <div class="boc-item1">
          <div class="fons1">今日订单数</div>
          <div class="tag">10单</div>
        </div> -->
      </el-card>
      <el-card class="a1">
        <div class="boc-item">
          <div class="fons">
            商品浏览数 | <span class="yesterday">{{ yesterdayTime }}</span>
          </div>
          <div class="tag">
            <el-tag class="cc" size="mini"> 全平台</el-tag>
          </div>
        </div>
        <div class="box-it">
          {{ total.goodsLookMap.all }}<span class="ftz">人</span> |
          {{ total.goodsLookMap.yesterday }}<span class="ftz">人</span>
        </div>
        <!-- <div class="boc-item1">
          <div class="fons1">今日订单数</div>
          <div class="tag">10单</div>
        </div> -->
      </el-card>
      <el-card class="a1">
        <div class="boc-item">
          <div class="fons">
            商品已加入购物车数 |
            <span class="yesterday">{{ yesterdayTime }}</span>
          </div>
          <div class="tag">
            <el-tag class="cc" size="mini"> 全平台</el-tag>
          </div>
        </div>
        <div class="box-it">
          {{ total.addCartMap.all }}<span class="ftz">个</span> |
          {{ total.addCartMap.yesterday }}<span class="ftz">个</span>
        </div>
        <!-- <div class="boc-item1">
          <div class="fons1">今日订单数</div>
          <div class="tag">10单</div>
        </div> -->
      </el-card>
      <el-card class="a1">
        <div class="boc-item">
          <div class="fons">
            购物车已删除商品数 |
            <span class="yesterday">{{ yesterdayTime }}</span>
          </div>
          <div class="tag">
            <el-tag class="cc" size="mini"> 全平台</el-tag>
          </div>
        </div>
        <div class="box-it">
          {{ total.noAddCartMap.all }}<span class="ftz">个</span> |
          {{ total.noAddCartMap.yesterday }}<span class="ftz">个</span>
        </div>
        <!-- <div class="boc-item1">
          <div class="fons1">今日订单数</div>
          <div class="tag">10单</div>
        </div> -->
      </el-card>
      <el-card class="a1">
        <div class="boc-item">
          <div class="fons">
            待支付订单数 | <span class="yesterday">{{ yesterdayTime }}</span>
          </div>
          <div class="tag">
            <el-tag class="cc" size="mini"> 全平台</el-tag>
          </div>
        </div>
        <div class="box-it">
          {{ total.orderNoLookNumMap.all }}<span class="ftz">个</span> |
          {{ total.orderNoLookNumMap.yesterday }}<span class="ftz">个</span>
        </div>
        <!-- <div class="boc-item1">
          <div class="fons1">今日订单数</div>
          <div class="tag">10单</div>
        </div> -->
      </el-card>
      <el-card class="a1">
        <div class="boc-item">
          <div class="fons">
            已支付订单数 | <span class="yesterday">{{ yesterdayTime }}</span>
          </div>
          <div class="tag">
            <el-tag class="cc" size="mini"> 全平台</el-tag>
          </div>
        </div>
        <div class="box-it">
          {{ total.orderSuccessNumMap.all }}<span class="ftz">个</span> |
          {{ total.orderSuccessNumMap.yesterday }}<span class="ftz">个</span>
        </div>
        <!-- <div class="boc-item1">
          <div class="fons1">今日订单数</div>
          <div class="tag">10单</div>
        </div> -->
      </el-card>
      <el-card class="a1">
        <div class="boc-item">
          <div class="fons">
            加入购物车最多商品 |
            <span class="yesterday">{{ yesterdayTime }}</span>
          </div>
          <div class="tag">
            <el-tag class="cc" size="mini"> 全平台</el-tag>
          </div>
        </div>
        <div class="box-it">
          <span style="font-size: 14px">{{ total.addMoreProductName }}</span>
        </div>
        <!-- <div class="boc-item1">
          <div class="fons1">今日订单数</div>
          <div class="tag">10单</div>
        </div> -->
      </el-card>
      <el-card class="a1">
        <div class="boc-item">
          <div class="fons">
            浏览次数最多商品 |
            <span class="yesterday">{{ yesterdayTime }}</span>
          </div>
          <div class="tag">
            <el-tag class="cc" size="mini"> 全平台</el-tag>
          </div>
        </div>
        <div class="box-it">
          <span style="font-size: 14px">{{ total.lookMoreProductName }}</span>
        </div>
        <!-- <div class="boc-item1">
          <div class="fons1">今日订单数</div>
          <div class="tag">10单</div>
        </div> -->
      </el-card>
    </div>
  </div>
</template>
<script>
import { zuJiDataSource } from "@/api/frontUser/traceLogs";
import { showMallList } from "@/api/system/user";
export default {
  name: "MallIndex",
  data() {
    return {
      total: {
        sendCouponMap: {
          all: "",
          yesterday: "",
        },
      },
      showSearch: true,
      range: [],
      queryParams: {
        startTime: null,
        endTime: null,
      },
      yesterdayTime: "",
      mallList: [],
    };
  },
  mounted() {
    this.getLogsTotal();
    this.yesterdayTime = this.getYesterdayTimestamp();
    //获取商城列表
    this.getMallList();
  },
  methods: {
    getMallList() {
      showMallList().then((res) => {
        this.mallList = res.data;
      });
    },
    getYesterdayTimestamp() {
      // 获取当前时间
      const now = new Date();
      // 设置为前一天
      now.setDate(now.getDate() - 1);
      // 转换为时间戳
      return this.parseTime(now.getTime(), "{y}-{m}-{d}");
    },
    handleQuery() {
      const [startTime, endTime] = this.range;
      this.queryParams.startTime = startTime;
      this.queryParams.endTime = endTime;
      this.getLogsTotal();
      if (this.range.length > 0) {
        this.yesterdayTime = startTime + " 至 " + endTime;
      } else {
        this.yesterdayTime = this.getYesterdayTimestamp();
      }
    },
    getLogsTotal() {
      zuJiDataSource(this.queryParams).then((res) => {
        this.total = res.data;
      });
    },
    resetQuery() {
      this.range = [];
      this.queryParams = {
        startTime: null,
        endTime: null,
      };
    },
  },
};
</script>
<style scoped lang="scss">
.box {
  margin: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  .a1 {
    width: 32%;
    margin: 10px 10px;
    .boc-item {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .fons {
        font-size: 18px;
        .yesterday {
          font-size: 14px;
        }
      }
    }
    .boc-item1 {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 17px;
      .fons1 {
        font-size: 14px;
      }
      .tag {
        font-size: 12px;
      }
    }
    .box-it {
      margin-top: 16px;
      border-top: 1px solid #eaeaea;
      border-bottom: 1px solid #eaeaea;
      padding: 18px 0;
      font-size: 36px;
      .ftz {
        font-size: 18px;
      }
    }
  }
}
.zhongj {
  margin: 0 20px 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .c1 {
    width: 33%;
    .hz {
      width: 100px;
      height: 100px;

      margin: 14px auto;
      // background-color: aqua;
      img {
        width: 100%;
        height: 100px;
      }
    }
    p {
      text-align: center;
    }
  }
}
</style>
